package utils;

import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedList;

import de.umass.lastfm.Album;
import de.umass.lastfm.Artist;
import de.umass.lastfm.Authenticator;
import de.umass.lastfm.PaginatedResult;
import de.umass.lastfm.Session;
import de.umass.lastfm.Track;
import de.umass.lastfm.User;

//Classe di supporto in cui vengono caricati i testi delle canzoni

public class Library {
	//Vecchia versione 
	public Collection<Track> getTracksOld() {
		String key = "7e5cff2998c3e3b558eddced33c028c3";      // api key
		Collection<Track> tracks = new LinkedList<Track>();
		Collection<Track> temp = null;
		temp = Artist.getTopTracks("Michael Jackson", key);
		Iterator<Track> iter = temp.iterator();
		Track track = null;
		while(iter.hasNext()){
			track = iter.next();
			if(!(track.getName().contains("-")||track.getName().contains("(")))
				tracks.add(track);
		}
		return tracks;
	}
	//Nuova versione che prende le track preferite di un utente
	public static Collection<Track> getTracks(){
		String key = "7e5cff2998c3e3b558eddced33c028c3";      // api key
	    String secret = "49822f97152f777e43e88eddd9a80377";   // api secret
	    String user = "marco_988";     // user name
	    String password = ""; // user's password(not necessary)
	    //Session session = Authenticator.getMobileSession(user, password, key, secret);
	    Collection<Track> newTracks = new LinkedList<Track>();
	    PaginatedResult<Track> tracks = User.getLovedTracks(user, key);
	    for(Track thisTrack: tracks){
	    	newTracks.add(thisTrack);
	    }
	    return newTracks;
	}
}
